package com.simple.elpmobile.onlinecase.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 时间格式化工具类
 * 
 * @author qingwu
 * 
 */
public class DateFormateUtil {

	public enum DateFormater {

		NORMAL("yyyy-MM-dd HH:mm"), DD("yyyy-MM-dd"), SS("yyyy-MM-dd HH:mm:ss");

		private String value;

		private DateFormater(String value) {
			this.value = value;
		}

		public String getValue() {
			return value;
		}
	}

	public static String getCurrentDateFormat(String pattern) {
		final DateFormat format = new SimpleDateFormat(pattern);
		return format.format(new Date());
	}

	public static String getDateFormat(String pattern, String time) {
		final DateFormat format = new SimpleDateFormat(pattern);
		Date date = null;
		try {
			date = format.parse(time);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return format.format(date);
	}

	/**
	 * 时间比较
	 * >0:oldTime > newTime <0:newTime > oldTime =0:newTime = oldTime
	 * @param oldTime
	 * @param newTime
	 * @return
	 */
	public static long timeCompare(String oldTime, String newTime) {
		SimpleDateFormat sdf = new SimpleDateFormat(DateFormater.SS.getValue());
		Date d1 = null, d2 = null;
		try {
			d1 = sdf.parse(oldTime);
			d2 = sdf.parse(newTime);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return d1.getTime() - d2.getTime();
	}
}
